<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>提问点名</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css"/>
		<link rel="stylesheet" href="../../css/weui.min.css" />
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<style type="text/css" media="screen">
			html, body {
				background-color: #f3f5f7;
			}
			.top-hand-div-style {
				text-align: center;
				margin-top: 20px;
				background-color: #FFFFFF;
				border: 2px solid #FFFFFF;
				border-radius: 6px;
				margin-right: 10px;
				margin-left: 10px;
				padding-top: 20px;
				padding-bottom: 20px;
			}
			.top-hand-img-style {
				width: 120px;
				height: 120px;
				border-radius: 60px;
				/*ox-shadow: 20px 0px 30px 10px #abcdef inset;*/
			}
			.top-hand-span-style {
				display: block;
				/*padding-bottom: 20px;*/
			}
			.middle-span-style {
				background: url(../../image/icon_ask_class.png) left center no-repeat;
				background-size: 20px;
				padding-left: 24px;
			}
			.name-middle-span-style {
				text-align: left;
			}
			.bottom-btn-div {
				position: fixed;
				bottom: 0px;
				width: 100%;
				background-color: #18b4ed;
				color: #FFFFFF;
				line-height: 40px;
				text-align: center;
				border: #18b4ed;
				display: none;
			}
			#middleDivId {
				margin-top: 20px;
				padding-bottom: 40px;
			}
			#askdiv {
				margin-right: 10px;
				margin-left: 10px;
				text-align: start;
				display: none;
			}
			#contentdiv {
				margin-top: 20px;
				margin-bottom: 50px;
				padding-right: 10px;
				padding-left: 10px;
				text-align: start;
				display: none;
			}
			.img_pic_style {
				max-width: 100%;
				padding-left: 10px;
				padding-right: 10px
			}
		</style>
	</head>
	<body>
		<div class="top-hand-div-style">
			<img src="../../image/icon_head_ask_class.png"  class="top-hand-img-style" id="headImgId"/>
			<span class="base_content_font base_black_grey top-hand-span-style" id="headNameId" > </span>
			<div id="askdiv">
				<span class="base_title_font base_black_grey " id="askNumId" > 提问(10人)</span>
				<div style="text-align: start;" id="askNameListId">
					<span class="base_content_font base_black_grey padding10 name-middle-span-style" id="askNameId"  >111111111111111</span>
					<span class="base_content_font base_black_grey padding10 name-middle-span-style" id="askNameId"  >8888</span>
				</div>
			</div>
		</div>
		<!--		<div class="top-hand-div-style"  id="middleDivId"    >-->
		<!--</div>-->
		<div id="contentdiv" class="top-hand-div-style"   >
			<span class="base_title_font base_black_grey " id="askNumId" > 提问内容</span>
			<p class="base_black_grey base_title_font padding10" id="content"></p>
			<div style="text-align: center;display:none;" id="div_img">
				<img src="../../image/course_placehoder.png" class="img_pic_style" id="qusestion_pic" />
			</div>
		</div>
		<button class="bottom-btn-div base_title_font" onclick="loaddata()" >
			开始提问
		</button>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript">
		var notNamearr = [];
		//未点名数组
		var Namearr = [];
		//已经点名的数组
		var num = 0;
		//判断是否加载已选的
		var pageparam = '';
		var timer;
		var time = 0;
		var xiabo = 0;
		apiready = function() {
			showProgress();
			pageparam = api.pageParam;
			//			 alert(JSON.stringify(pageparam));
			getNamesList();
			setupNotifi();
			setRefreshHeader();
			getdataQusertion();
			if (pageparam.type == 0) {//未开始
			    sendBuriedNotifi('0', '老师端提问结果页', '204');
				$(".bottom-btn-div").show();
			} else if (pageparam.type == 1) {//经行中
			sendBuriedNotifi('0', '老师端提问结果页', '204');
				$("#middleDivId").show();
				$(".bottom-btn-div").show();
			} else if (pageparam.type == 3) {//学生
				sendBuriedNotifi('0', '学生端提问页', '180');
				$(".bottom-btn-div").hide();
			}
		};
		
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				getNamesList();
			});
		}

		function setupNotifi() {
			api.addEventListener({
				name : 'pushMessage_classroomMessage'
			}, function(ret, err) {
				//		 alert(JSON.stringify(ret.value));
				if (TW_TYPE == ret.value.type && $api.getStorage('cfnetppjxid') == ret.value.jid && api.pageParam.id == ret.value.id) {
					if (ret.value.status == 3 && pageparam.type == 3) {//点名
						getNamesList();
					}
				}
			})
		}

		/**
		 *获取学生名单
		 * iid 提问id
		 * tid 类型
		 *  */
		function getNamesList() {
			var params = {
				jid : $api.getStorage('cfnetppjxid'),
				iid : api.pageParam.id,
				tid : 2,
			}
			//			 alert(JSON.stringify(params));
			cfnetppPOST(url_getaskNameList, params, true, function(data, status) {
				//			alert(JSON.stringify(data));
				api.hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
						var datas = data.data;
						notNamearr = datas.wtw;
						arrContainEle(datas, 'ytw');
						Namearr = datas.ytw;
						$("#askNumId").html("提问(" + Namearr.length + "人)");
						addAskName(Namearr, Namearr.length);
					} else {
					}
				} else {
				}
			})
		}

		/**
		 *点名
		 * iid 提问id
		 * tid 类型
		 * stuid  学生id
		 *  */
		function getDoName(id) {
			//		alert(stuid)
			showProgress();
			var params = {
				iid : api.pageParam.id,
				tid : 2,
				stuid : notNamearr[xiabo].stuid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			}
			cfnetppPOST(url_doAsk, params, true, function(data, status) {
				//				api.hideProgress();
				
               SendBusinessOperationsLogNotifi('老师端提问点名', '204', params, params, '', data, '老师端提问点名接口', '204-01')
				if (status == 'success') {
					if (data.code == 200) {
						getNamesList();
						//					   var Namehtml = '<span class="base_content_font base_black_grey padding10 name-middle-span-style" id="askNameId" >'+ notNamearr[xiabo].stuname+'</span>'
						//					  alert(Namehtml);
						//					   $("#askNameListId").append(Namehtml);
						$('.bottom-btn-div').removeAttr("disabled");
						//移除disabled属性
					}
				}
			})
		}

		function loaddata() {
			if (notNamearr.length > 0) {
				$('.bottom-btn-div').attr('disabled', "true");
				//添加disabled属性
				time = 5;
				timeCountDown();
				timer = setInterval(timeCountDown, 1000);
			} else {
				ShowToast("该项活动无学生")
			}
		}

		function timeCountDown() {
			if (time == 0) {
				clearInterval(timer);
				getDoName(xiabo);
				return true;
			}
			time--;
			var len = notNamearr.length;
			xiabo = parseInt(len*Math.random()); //产生随机数
			var stuname = notNamearr[xiabo].stuname;
			var stupic = notNamearr[xiabo].picurl;
			$("#headImgId").attr("src",headImgUrl(stupic));
			$("#headNameId").html(stuname);
				//倒计时
			return false;
			}
		function headImgUrl(img) {
			var str = img;
			if (str == null || str == undefined || str == '') {
				return '../../image/icon_head_ask_class.png';
			}
			if (str.substr(0, 7) == "http://") {
				return str
			} else {
				return 'http://cfnet.org.cn/data/uploads/' + str;
			}
		}

		//添加已经点名的
		function addAskName(data, len) {
			if (len > 0) {
				$("#askdiv").show();
				if (pageparam.type == 3) {//学生
					//	    alert(JSON.stringify(data[len-1]));
					$("#headImgId").attr("src", headImgUrl(data[len - 1].picurl));
					$("#headNameId").html(data[len - 1].stuname);
				}
			}
			var stumanes = '';
			for ( i = 0; i < len; i++) {
				stumanes += '<span class="base_content_font base_black_grey padding10 name-middle-span-style" id="askNameId" >' + data[i].stuname + '</span>';
			}
			$("#askNameListId").html(stumanes);
			//		   $("#askNameId").html(stumanes.substring(0,stumanes.length-1));
			//	    }
		}

		//获取问题数据
		function getdataQusertion() {
			var params = {
				iid : api.pageParam.id,
				tid : 2
			}
			cfnetppPOST(url_ActiveInfo, params, true, function(data, status) {
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						//					alert("44");
						setQusetionData(data.data);
					} else if (data.code = 108) {
						$('#noData').show();
						$('#noNet').hide();
						$('#mian').hide();
					} else {
						$('#noData').hide();
						$('#noNet').show();
						$('#mian').hide();
					}
				}
			})
		}

		function setQusetionData(data) {
			//		   $('#title').text(data.name+"提问中");
			//           alert(data.upfile);
			if (data.upfile != '' && data.upfile != null) {
				$('#div_img').show();
				$('#qusestion_pic').attr('src', data.upfile);
				$("#qusestion_pic").click(function() {
					var imgArr = new Array();
					imgArr.push(data.upfile);
					showimg(imgArr, 0);
				});
			}
			var content = data.content + '';
			if (content != '' && content != null) {
				$('#content').text(content);
				$('#contentdiv').show();
			} else {
				if (data.upfile != '' && data.upfile != null) {
					$('#contentdiv').show();
				} else {
					$('#contentdiv').hide();
				}
			}
		}
	</script>
</html>